﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BruteForceSerializer.Formatting;
using BruteForceSerializer.Normalization;
using NUnit.Framework;

namespace BruteForceSerializer.Tests
{
    [TestFixture]
    public class test_Formatter
    {
        [Test]
        public void Objekt_mit_Feld()
        {
            var no = new NormalizedObject(typeof(string), 0);
            no.AddField("f1", 42);

            var formattedObject = Formatter.Format(no, false);

            Assert.AreEqual(@"{""_Id"":0,""_Type"":""String"",""f1"":42}", formattedObject);
        }

        [Test]
        public void Geschachtelte_Objekte()
        {
            var noParent = new NormalizedObject(typeof (string), 0);
            var noChild = new NormalizedObject(typeof (int), 1);
            noParent.AddField("child", noChild);

            var formattedObject = Formatter.Format(noParent, false);

            Assert.AreEqual(@"{""_Id"":0,""_Type"":""String"",""child"":{""_Id"":1,""_Type"":""Int32""}}", formattedObject);
        }

        [Test]
        public void Objektreferenzen()
        {
            var noParent = new NormalizedObject(typeof(string), 0);
            var noRef = new NormalizedReference(99);
            noParent.AddField("someObject", noRef);

            var formattedObject = Formatter.Format(noParent, false);

            Assert.AreEqual(@"{""_Id"":0,""_Type"":""String"",""someObject"":{""_ObjectId"":99}}", formattedObject);
        }
    }
}
